package offer;

/**
 *剑指 Offer 17. 打印从1到最大的n位数
 */
public class PrintNumbers {

    public static int n = 2;
    public static int i = 0;
    public static StringBuffer bf = new StringBuffer();
    public static char[] loop = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
    public static char[] chars = new char[2];

    public static void main(String[] args) {
//        int[] ints = printNumbers(1);
//        for (int anInt : ints) {
//            System.out.println(anInt);
//        }
        new PrintNumbers().dfs(0);
    }

    public static int[] printNumbers(int n) {
        int target = 1;

        for (int i = 1; i <= n; i++) {
            target *= 10;
        }
        int[] arr = new int[target - 1];
        for (int i = 1; i < target; i++) {
            arr[i - 1] = i;
        }
        return arr;
    }


    public void dfs(int x) {
        if (x == n) {
            System.out.println(new String(chars));
            return;
        }
        for (int i = x; i < loop.length; i++) {
            chars[x] = loop[i];
            dfs(x + 1);
        }
    }
}
